package com.cxyd.generator.test;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

/**
 * @Author: huanglianyun
 * @Description:
 * @DATE: Created in 2020/5/3 19:10.
 */
public class WrapperTest extends BaseTest{

    /**
     * <p>
     * 根据 entity 条件，查询一条记录,
     * 这里和上方删除构造条件一样，只是seletOne返回的是一条实体记录，当出现多条时会报错
     * </p>
     */
    @Test
    public void selectOne() {
        /*QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", "lqf");

        User user = mapper.selectOne(queryWrapper);
        System.out.println(user);*/
    }

    @Test
    public void test2(){
        /*LambdaQueryWrapper<ProjectUser> lwq = Wrappers.lambdaQuery();
        lwq.eq(ProjectUser::getUserId,user.getUserId());
        lwq.eq(ProjectUser::getProjectId,information.getProjectId());
        projectUserMapper.delete(lwq);*/
        String s = JSONObject.toJSONString(null);
        JSONObject jsonObject = JSONObject.parseObject(s);
        Object aa = jsonObject.get("aa");
    }

    /**
     * 设置查询字段
     * 说明:
     *
     * 以上方分法为两类.
     * 第二类方法为:过滤查询字段(主键除外),入参不包含 class 的调用前需要wrapper内的entity属性有值!
     * 这两类方法重复调用以最后一次为准
     */
    /*只显示某两个字段

    @Test
    public void selectByWrapper10() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("name", "age").like("name", "雨");
        List<User> users = userMapper.selectList(queryWrapper);
        users.forEach(System.out::println);
    }



    显示除了某两个字段,其他所有字段.
    @Test
    public void selectByWrapper11() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.select(User.class, info -> !info.getColumn().equals("manager_id")
                && !info.getColumn().equals("create_time"));
        List<User> users = userMapper.selectList(queryWrapper);
        users.forEach(System.out::println);
    }*/

}
